package mess;

public class LeeCode_777 {
    public static void main(String[] args) {
        //System.out.println(canTransform("RXXLRXRXL", "XRLXXRRLX"));
        //System.out.println(canTransform("X", "L"));
        System.out.println(canTransform("XRXXXLXXXR",
                "XXRLXXXRXX"));
    }

    private static boolean canTransform(String start, String end) {
        int i = 0, j = 0;
        int lenS = start.length();
        int lenE = end.length();
        if (lenS != lenE)
            return false;
        while (i < lenS && j < lenS) {
            while (i < lenS && start.charAt(i) == 'X') {
                i++;
            }
            while (j < lenS && end.charAt(j) == 'X') {
                j++;
            }
            if (i < lenS && j < lenS) {
                if (start.charAt(i) != end.charAt(j)) {
                    return false;
                } else if ((start.charAt(i) == 'L' && i < j) || (start.charAt(i) == 'R' && i > j)) {
                    return false;
                }
                i++;
                j++;
            }
        }
        while (i < lenS) {
            if (start.charAt(i) != 'X')
                return false;
            i++;
        }
        while (j < lenS) {
            if (end.charAt(j) != 'X')
                return false;
            j++;
        }
        return true;
    }
}



